//
//  YCommentUserView.m
//  yuimall_Iphone
//
//  Created by yuike6 yuike6 on 12-4-14.
//  Copyright (c) 2012年 yuike. All rights reserved.
//

#import "YCommentUserView.h"
#import "header.h"
#import "AsyncImageView.h"

@implementation YCommentUserView
@synthesize commentData = commentData_;

@synthesize userImageView = userImageView_;
@synthesize nickView = nickView_;

-(void) dealloc
{
    YRelease(commentData_)
    
    YRelease(userImageView_)
    YRelease(nickView_)
    [super dealloc];
}

-(void) setCommentData:(YCommentModel *)commentDataValue
{
    YRelease(commentData_)
    commentData_ = [commentDataValue retain];
    
    if (!commentDataValue) {
        return;
    }
    
    if (commentDataValue.user.userImage) {
        [self.userImageView setImage:commentDataValue.user.userImage];
    }
    else if(![NSString isNilOrEmpty:commentDataValue.user.userImageUrl]){
        // to do...
        // get user image by network;
        [self.userImageView loadImageWithURLString:commentDataValue.user.userImageUrl];        
    }
    
    [self.nickView setText:commentDataValue.user.nick];
}

-(void) privateInit
{
    if (self.bInited) {
        return;
    }
    
    AsyncImageView * tmp_imageview = [[AsyncImageView alloc] init];
    self.userImageView = tmp_imageview;
    YRelease(tmp_imageview);
    [self addSubview:self.userImageView];    
    
    UILabel * tmp_nick = [[UILabel alloc] init];
    [tmp_nick setFont:[UIFont systemFontOfSize:10]];
    [tmp_nick setTextAlignment:UITextAlignmentCenter];
    [tmp_nick setTextColor:COLOR_GRAY];
    tmp_nick.lineBreakMode = UILineBreakModeCharacterWrap;     
    tmp_nick.numberOfLines = 0;
    self.nickView = tmp_nick;
    YRelease(tmp_nick);
    [self addSubview:self.nickView];
    
    [self reAdjustLayout];
    self.bInited = TRUE;    
}

-(id) init
{
    self = [super init];
    if (self) {
        [self privateInit];
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self privateInit];
    }
    return self;
}


-(void) reAdjustLayout
{
    [self.userImageView setFrame:CGRectMake(self.width / 5, 
                                            10, 
                                            self.width / 5 * 3, 
                                            self.width / 5 * 3)];
    
    [self.nickView setFrame:CGRectMake(0, 
                                       self.userImageView.frame.origin.y + self.userImageView.frame.size.height + 10,
                                       self.width, 15)];
    
    // level
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
